// forget to high Precision, so maybe use java BigInteger
//
// run: $exec < input
#include <cstdio>
#include <algorithm>

struct data { int v, p; };

bool operator<(data const & a, data const & b)
{
	return a.v < b.v || (a.v == b.v && a.p > b.p);
}

int const maxn = 50100;
data da[maxn];
long long bit[maxn][7];
int n, m = 5;

int lowbit(int x) { return x & -x; }

int prefix_sum(int k, int id)
{
	long long sum = 0;
	for (; id > 0; id -= lowbit(id)) sum += bit[id][k];
	return sum;
}

void update(int k, int id, int delta)
{
	for (; id <= n; id += lowbit(id)) bit[id][k] += delta;
}

int main()
{
	while (std::scanf("%d", &n) != EOF) {
		for (int i = 1; i <= n; i++) {
			std::scanf("%d", &da[i].v);
			for (int j = 1; j < m; j++) bit[i][j] = 0;
			da[i].p = i;
		}
		std::sort(da + 1, da + n + 1);

		long long ans = 0;
		for (int i = 1; i <= n; i++) {
			update(1, da[i].p, 1);
			for (int j = 2; j <= m; j++) {
				long long sum = prefix_sum(j - 1, da[i].p - 1);
				if (j == m) ans += sum;
				else update(j, da[i].p, sum);
			}
		}
		std::printf("%lld\n", ans);
	}
}

